package com.welkom.everydate.util.web;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class PageData<T> implements Serializable{
	private int pageSize=10;
	private int currentPage=1;
	private int totalCount=0;
	private int totalPage=0;
	private int startIndex=0;
	private int pageNavigatorLength=0;
	private int currentPageSize;
	private boolean isLastPage;
	private List<T> data=new ArrayList<T>();
	private List<Operation> operations;
	private List<PageHeader> pageHeaders;
	public PageData(int pageSize, int currentPage, int totalCount,
			int totalPage, List<T> data,int startIndex,List<Operation> operations) {
		this.pageSize = pageSize;
		this.currentPage = currentPage;
		this.totalCount = totalCount;
		this.totalPage = totalPage;
		this.data = data;
		this.startIndex=startIndex;
		this.operations=operations;
	}
	public PageData() {
		
	}
	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}
	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	/**
	 * @return the currentPage
	 */
	public int getCurrentPage() {
		return currentPage;
	}
	/**
	 * @param currentPage the currentPage to set
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	/**
	 * @return the totalCount
	 */
	public int getTotalCount() {
		return totalCount;
	}
	/**
	 * @param totalCount the totalCount to set
	 */
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	/**
	 * @return the totalPage
	 */
	public int getTotalPage() {
		if(this.totalPage!=0){
		return totalPage;
		}else{
			if(this.totalCount%this.pageSize==0){
				this.totalPage=this.totalCount/this.pageSize ;
			}else{
				this.totalPage=(this.totalCount/this.pageSize)+1;
			}
		return this.totalPage;
		}
	}
	/**
	 * @param totalPage the totalPage to set
	 */
	public void setTotalPage(int totalPage) {
		if(this.totalCount%this.pageSize==0){
			this.totalPage=this.totalCount/this.pageSize ;
		}else{
			this.totalPage=(this.totalCount/this.pageSize)+1;
		}
	}
	/**
	 * @return the data
	 */
	public List<T> getData() {
		return data;
	}
	/**
	 * @param data the data to set
	 */
	public void setData(List<T> data) {
		this.data = data;
	}
	/**
	 * @return the startIndex
	 */
	public int getStartIndex() {
		
		return (currentPage-1)*pageSize;
	}
	
	/**
	 * @param startIndex the startIndex to set
	 */
	public void setStartIndex(int startIndex) {
		this.startIndex = (currentPage-1)*pageSize;
	}
	/**
	 * @return the operations
	 */
	public List<Operation> getOperations() {
		return operations;
	}
	/**
	 * @param operations the operations to set
	 */
	public void setOperations(List<Operation> operations) {
		this.operations = operations;
	}
	/**
	 * @return the currentPageSize
	 */
	public int getCurrentPageSize() {
		int currentPageSize=0;
		if(this.getCurrentPage()!=this.getTotalPage()){
			currentPageSize=this.getPageSize();
		}else{
			currentPageSize=this.getTotalCount()-this.getTotalPage()*(this.getPageSize()-1);
		}
		return currentPageSize;
	}
	/**
	 * @param currentPageSize the currentPageSize to set
	 */
	public void setCurrentPageSize(int currentPageSize) {
		if(this.getCurrentPage()!=this.getTotalPage()){
			currentPageSize=this.getPageSize();
		}else{
			currentPageSize=this.getTotalCount()-this.getTotalPage()*(this.getPageSize()-1);
		}
	}
	/**
	 * @return the isLastPage
	 */
	public boolean isLastPage() {
		return this.getTotalPage()==this.getCurrentPage()?true:false;
	}
	/**
	 * @param isLastPage the isLastPage to set
	 */
	public void setLastPage(boolean isLastPage) {
		this.isLastPage =( this.getTotalPage()==this.getCurrentPage()?true:false);
	}
	/**
	 * @return the pageNavigatorLength
	 */
	public int getPageNavigatorLength() {
		return pageNavigatorLength;
	}
	/**
	 * @param pageNavigatorLength the pageNavigatorLength to set
	 */
	public void setPageNavigatorLength(int pageNavigatorLength) {
		this.pageNavigatorLength = pageNavigatorLength;
	}
	/**
	 * @return the pageHeaders
	 */
	public List<PageHeader> getPageHeaders() {
		if(pageHeaders==null){
			pageHeaders=PageHeaderAnnotationResolver.getHeadersFromDomain(getClass().getGenericSuperclass().getClass());
		}
		return pageHeaders;
	}
	/**
	 * @param pageHeaders the pageHeaders to set
	 */
	public void setPageHeaders(List<PageHeader> pageHeaders) {
		this.pageHeaders=pageHeaders;
	}
	
	
}
